<template>
  <el-form>
    <el-form-item label="昵称">
      <el-input v-model.trim="user.name" />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submit">修改</el-button>
    </el-form-item>
  </el-form>
</template>

<script>

  import {update} from '../../../api/user.js'
export default {
  data(){
    return {
      password:''
    }
  },
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          name: '',
          email: ''
        }
      }
    }
  },
  methods: {
    submit() {
      if (this.name == '') {
        this.$message({
		  message: '昵称不能为空',
		  type: 'warning'
		});
        return
      }
      update(this.user.name).then(res => {
          if (res.code == 20000) {
            this.$message({
              message: res.data,
              type: 'success',
              duration: 5 * 1000
            })
          } else {
            this.$message({
              message: res.data,
              type: 'warning',
              duration: 5 * 1000
            })
          }
      }).catch(err => {
          this.$message({
            message: '更新异常',
            type: 'error',
            duration: 5 * 1000
          })
      })

    }
  }
}
</script>
